# coding=utf-8
import allure
smoke_base = __import__('case.98_smoke.smoke_base') # 如果有数字开头的引入包，只能用__import__()方式引入
from smoke_base import SmokeBase
import pytest
from common.db import *
from common.read_yaml import ReadYaml
data = ReadYaml().get_yaml_data(f'{os.path.abspath(__file__).split("_test.py")[0]}.yml')   # 读取数据

# 用于并发跑消息和事件时使用
# import datetime
# delay = (datetime.datetime.now()+datetime.timedelta(hours=1)).timestamp()

@pytest.mark.usefixtures('init_environment')    #执行环境初始化的fixture
@allure.feature('测试发起加签驳回作废终止审批归档的连续审批')  # 测试报告显示测试功能
class Test_Create_And_Approve(SmokeBase):

    # 获取yml文件中initiate_process的数据参数
    initiate_process_params = data['initiate_process']
    # 获取yml的title，并作为ids的值传给用例
    ids_list = jsonpath.jsonpath(initiate_process_params,"$[*][0]")
    @pytest.mark.parametrize("title, param, expect", initiate_process_params,ids=ids_list)
    def test_create_process(self, user_login, title, param, expect):
        Logger.info("*************** {}开始执行用例 ***************".format(title))
        allure.dynamic.description(f"{param['description']}")  # 动态解析用例描述在测试报告中展示
        # while(datetime.datetime.now().timestamp() < delay):
        self.approve(param, user_login)
        Logger.info("*************** {}结束执行用例 ***************".format(title))

    # 获取yml文件中initiate_terminal的数据参数
    initiate_process_params = data['initiate_terminal']
    # 获取yml的title，并作为ids的值传给用例
    ids_list = jsonpath.jsonpath(initiate_process_params,"$[*][0]")
    @pytest.mark.parametrize("title, param, expect", initiate_process_params,ids=ids_list)
    def test_create_process_2(self, user_login, title, param, expect):
        Logger.info("*************** {}开始执行用例 ***************".format(title))
        allure.dynamic.description(f"{param['description']}")  # 动态解析用例描述在测试报告中展示
        # while (datetime.datetime.now().timestamp() < delay):
        self.approve(param, user_login)
        Logger.info("*************** {}结束执行用例 ***************".format(title))

    # # 获取yml文件中initiate_rollback的数据参数
    # initiate_process_params = data['initiate_rollback']
    # # 获取yml的title，并作为ids的值传给用例
    # ids_list = jsonpath.jsonpath(initiate_process_params,"$[*][0]")
    # @pytest.mark.parametrize("title, param, expect", initiate_process_params,ids=ids_list)
    # def test_create_process_3(self, user_login, title, param, expect):
    #     Logger.info("*************** {}开始执行用例 ***************".format(title))
    #     allure.dynamic.description(f"{param['description']}")  # 动态解析用例描述在测试报告中展示
    #     # while (datetime.datetime.now().timestamp() < delay):
    #     self.approve(param, user_login)
    #     Logger.info("*************** {}结束执行用例 ***************".format(title))

    # 获取yml文件中initiate_cancel的数据参数
    initiate_process_params = data['initiate_cancel']
    # 获取yml的title，并作为ids的值传给用例
    ids_list = jsonpath.jsonpath(initiate_process_params,"$[*][0]")
    @pytest.mark.parametrize("title, param, expect", initiate_process_params,ids=ids_list)
    def test_create_process_4(self, user_login, title, param, expect):
        Logger.info("*************** {}开始执行用例 ***************".format(title))
        allure.dynamic.description(f"{param['description']}")  # 动态解析用例描述在测试报告中展示
        # while (datetime.datetime.now().timestamp() < delay):
        self.approve(param, user_login)
        Logger.info("*************** {}结束执行用例 ***************".format(title))

if __name__=="__main__":
    pytest.main(['-s',r'D:\PycharmProjects\API-automation\case\test_01_initiate_process\test_01_initiate_interface.py'])